/*
 * Copyright (c) 2022-2022 All rights Reserved.
 */

package com.driving.core.mapper.type;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonValue;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

/**
 * 性别
 *
 * @author SAGITTAR
 * @since 2017
 */
@Getter
@RequiredArgsConstructor
public enum Gender implements IEnum<String> {

    /**
     * 男
     */
    MALE(1, "male", "男"),
    /**
     * 女
     */
    FEMALE(2, "female", "女");

    private final int sexValue;

    private final String sexString;

    @JsonValue
    private final String description;

    @Override
    public String getValue() {
        return sexString;
    }

    public static Gender from(@NonNull Integer sex) {
        Gender gender = null;
        for (Gender current : values()) {
            if (current.sexValue == sex) {
                gender = current;
                break;
            }
        }
        return gender;
    }

    public static Gender of(@NonNull String sex) {
        Gender gender = null;
        for (Gender current : values()) {
            if (current.sexString.equalsIgnoreCase(sex)) {
                gender = current;
                break;
            }
        }
        return gender;
    }
}
